package struts.action.etudiant;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import metier.Entreprise;
import metier.Etudiant;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import dao.DAOEtudiant;

public class ActionListeEntreprises extends Action {
	
	private DAOEtudiant daoEtudiant=null;

	public DAOEtudiant getDaoEtudiant() {
		return daoEtudiant;
	}

	public void setDaoEtudiant(DAOEtudiant daoEtudiant) {
		this.daoEtudiant = daoEtudiant;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		HttpSession session = request.getSession(false);
		
		Etudiant etud = (Etudiant) session.getAttribute("etudiant");
		
		if(etud == null)
			return mapping.findForward("fatalError");
		
		ArrayList<Entreprise> liste = getDaoEtudiant().listerEntreprises();
		
		request.setAttribute("ENTREPRISES", liste);
		
		if(liste.size()== 0)
		{
			request.setAttribute("NOTHING", "Il n'y a aucune entreprise proposant de stage");
			return mapping.findForward("afficherListe");
		}
		
		return mapping.findForward("afficherListe");
	}
	
	

}
